﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using ZCConsole.Load;
using ZCConsole.VOBC;

namespace ZCConsole
{
    public class ZC
    {
        public StationElements data;

        //public bool IsShowLog = false;
        public bool IsSaveLog = false;

        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        public static extern bool AllocConsole();

        // 释放控制台
        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        public static extern bool FreeConsole();

        private ZCSocket zcSock;

        public void Initialize()
        {
            try
            {
                data = new StationElements();
                data.LoadDevices("StationElements.xml");
                data.LoadTopo("StationTopoloty.xml");
                data.LoadRoutes("RouteList.xml");
                data.ClearEmptyNode();
            }
            catch (Exception ex)
            {
                LogHelper.LogError("配置文件加载错误！", ex);
            }
            LogHelper.LogInfo("配置文件加载完成。");
            
            IPConfigure LoadIPConfig = new IPConfigure();

            new LoadSectionRelay(this);
            zcSock = new ZCSocket(this);
        }

        public void Start()
        {
            zcSock.Start();
            new NonCommunicationTrain(zcSock.VOBCorCI.VOBC, this, zcSock.VOBCorCI.updateRoute, zcSock.VOBCorCI.updateTrain);
        }
    }
}
